using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
namespace MicroMsg.UI.UserContrl
{
	public class ContactUpdatedService
	{
		private const string TAG = "ContactUpdatedService";
		public List<ContactItemInterface> mDataList = new List<ContactItemInterface>();
		private EventWatcher mWatcherContactUpdate;
		private bool isHeadInit;
		public ContactUpdatedService()
		{
			this.WatcherInit();
		}
		public void Add(ContactItemInterface itemObject)
		{
			if (itemObject == null)
			{
				return;
			}
			if (this.mDataList == null)
			{
				return;
			}
			if (this.mDataList.Contains(itemObject))
			{
				return;
			}
			this.mDataList.Add(itemObject);
		}
		public void Delete(ContactItemInterface itemObject)
		{
			if (itemObject == null)
			{
				return;
			}
			if (this.mDataList == null)
			{
				return;
			}
			if (!this.mDataList.Contains(itemObject))
			{
				return;
			}
			this.mDataList.Remove(itemObject);
		}
		private void WatcherInit()
		{
			if (this.isHeadInit)
			{
				return;
			}
			this.mWatcherContactUpdate = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerContactUpdate));
			EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatcherContactUpdate);
			EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_MODIFY, this.mWatcherContactUpdate);
			this.isHeadInit = true;
		}
		private void WatcherUnit()
		{
			if (!this.isHeadInit)
			{
				return;
			}
			EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatcherContactUpdate);
			EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_MODIFY, this.mWatcherContactUpdate);
			Log.smethod_5("ContactUpdatedService", "removeEventWatcher EventConst.ON_MGR_HEAD_IMG_READY");
			this.isHeadInit = false;
		}
		private void onEventHandlerContactUpdate(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			List<Contact> listObject = evtArgs.getListObject<Contact>();
			if (listObject == null)
			{
				return;
			}
			if (this.mDataList == null)
			{
				return;
			}
			using (List<Contact>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Contact current = enumerator.get_Current();
					if (current != null && current.GetType() == typeof(Contact))
					{
						using (List<ContactItemInterface>.Enumerator enumerator2 = this.mDataList.GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								ContactItemInterface current2 = enumerator2.get_Current();
								if (current2.UserName == current.strUsrName)
								{
									current2.ContactDataUpdated();
								}
							}
						}
					}
				}
			}
		}
	}
}
